package com.dylan.job.trigger;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author dylan
 * @description 触发器辅助工具
 * @date 2025/2/9  22:13
 */
@Slf4j
public class JobTriggerPoolHelp {

    private ThreadPoolExecutor poolExecutor;

    private final static JobTriggerPoolHelp helper = new JobTriggerPoolHelp();

    private JobTriggerPoolHelp() {
    }

    public void start() {
        poolExecutor = new ThreadPoolExecutor(150, 200, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<>(20000), new RejectedExecutionHandler() {
            @Override
            public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                log.error("线程池处理数据太慢...无法接收新任务");
            }
        });
    }

    public static void trigger(Integer jobId) {
        helper.addTrigger(jobId);
    }

    private void addTrigger(Integer jobId) {
        poolExecutor.execute(new Runnable() {
            @Override
            public void run() {

            }
        });
    }
}
